//
//  PageSegmentItemViewCell.swift
//  PageNavigator
//
//  Created by 张奇 on 2025/8/13.
//

import UIKit

// SegmentItem 的cell 通用用来加载view， 并提供给用户渲染
class SegmentItemViewCell: UICollectionViewCell {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    private var view: SegmentItemViewProtocol?
    
    func displayItemView(_ view: SegmentItemViewProtocol) {
       
        if let old = self.view {
            old.removeFromSuperview()
        }
        self.contentView.addSubview(view)
        self.view = view
    }
    
    func endDisplayItemView(_ view: SegmentItemViewProtocol) {
        self.view = nil
        view.removeFromSuperview()
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        if let view = self.view {
            view.frame = self.contentView.bounds
        }
    }
}
